package com.shop.admin.controller;

import com.shop.admin.result.ApiResult;
import com.shop.admin.service.TakeoutGoodsService;
import com.shop.admin.utils.PageUtils;
import com.shop.admin.valid.AddGroup;
import com.shop.admin.vo.OrderVo;
import com.shop.admin.vo.TakeoutGoodsSpecificationVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Map;

@Api(tags = {"TakeoutGoodsController"},description = "外卖商家商品接口")
@RestController
@RequestMapping("/api/takeout/goods")
public class TakeoutGoodsController {

    @Resource
    private TakeoutGoodsService takeoutGoodsService;

    /**
     * 根据商家id查询商家的商品详情
     */
    @PostMapping("/list")
    @ApiOperation(value = "post商品详情条件查询（商品名称name，秒杀标记seckill，分类名称categoryName,销量查询（月查询（sales_month_volume）或者总查询（sales_volume））",notes = "page,limit,merchantId商家id，商品名称，商品价格，秒杀标记 0->普通商品 1->秒杀商品，秒杀价格，商品图片，商品库存,销量,月销量,描述,商户名称,商户id,数据入库时间,分类id,分类名称")
    public ApiResult list(@ApiParam("参数为：page,limit,id,name,price,seckill,priceSeckil,images,inStocks,salesVolume,salesMonthVolume,description,merchantName,merchantId,insertTime,categoryId,categoryName")@RequestBody Map<String, Object> params){
        PageUtils page = takeoutGoodsService.queryPage(params);
        return ApiResult.ok(page);
    }

    /**
     * 删除商家商品
     */
    @PostMapping("/delete")
    @ApiOperation(value = "商家商品删除",notes = "商品id数组")
    public ApiResult delete(@ApiParam("参数为：id")@RequestBody Long[] ids){
        takeoutGoodsService.removeMenuByIds(Arrays.asList(ids));
        return ApiResult.ok("删除成功！");
    }

    /**
     * 根据商品id查看商品的参数及规格
     */
    @GetMapping("/specification")
    @ApiOperation(value = "商家商品参数及规格",notes = "商品id数组")
    public ApiResult takeoutGoodsById(@ApiParam("参数为：takeoutGoodsId")@RequestParam("takeoutGoodsId") Integer takeoutGoodsId){
        TakeoutGoodsSpecificationVo vos = takeoutGoodsService.takeoutGoodsById(takeoutGoodsId);
        return ApiResult.ok(vos);
    }
}
